import request from '@/utils/request'

export interface UserVO {
  id: number
  username: string
  nickname: string
  deptId: number
  postIds: string[]
  email: string
  mobile: string
  sex: number
  avatar: string
  loginIp: string
  status: number
  remark: string
  loginDate: Date
  createTime: Date
}

// 查询用户管理列表
export const getUserPage = (params: any) => {
  return request({
    url: '/system/user/page',
    method: 'GET',
    params,
  })
}

// 查询用户管理列表
export const getRoleUserPage = (params: any) => {
  return request({
    url: '/system/user/role-User-Page',
    method: 'GET',
    params,
  })
}

// 增加用户列表
export const getOpt = () => {
  return request({
    url: '/system/user/opt',
    method: 'GET',
  })
}

// 查询所有用户列表
export const getAllUser = () => {
  return request({
    url: '/system/user/list-all-simple',
    method: 'GET',
  })
}

// 查询用户详情
export const getUserById = (id: number) => {
  return request({
    url: `/system/user/getUserById?id=${id}`,
    method: 'GET',
  })
}

// 查询用户详情
export const getUser = (id: number) => {
  return request({
    url: `/system/user/get?id=${id}`,
    method: 'GET',
  })
}

// 新增用户
export const saveOrUpdateUser = (data: UserVO) => {
  return request({
    url: '/system/user/saveOrUpdate',
    method: 'POST',
    data,
  })
}

// 新增用户
export const createUser = (data: UserVO) => {
  return request({
    url: '/system/user/create',
    method: 'POST',
    data,
  })
}

// 修改用户
export const updateUser = (data: UserVO) => {
  return request({
    url: '/system/user/update',
    method: 'PUT',
    data,
  })
}

// 删除用户
export const deleteUser = (id: number) => {
  return request({
    url: `/system/user/delete?id=${id}`,
    method: 'DELETE',
  })
}

// 批量删除用户
export const deleteUsers = (data: any) => {
  return request({
    url: `/system/user/deletes`,
    method: 'DELETE',
    data,
  })
}

// 用户迁移
export const getUserMobility = (deptId: number, data: any) => {
  return request({
    url: `/system/user/getUserMobility?deptId=${deptId}`,
    method: 'POST',
    data,
  })
}

// 导出用户
export const exportUser = (params) => {
  return request({
    url: '/system/user/export',
    method: 'GET',
    responseType: 'blob',
    params,
  })
}

// 下载用户导入模板
export const importUserTemplate = () => {
  return request({
    url: '/system/user/get-import-template',
    method: 'GET',
    responseType: 'blob',
  })
}

// 用户密码重置
export const resetUserPwd = (id: number, password: string) => {
  const data = {
    id,
    password,
  }
  return request({
    url: '/system/user/update-password',
    method: 'PUT',
    data,
  })
}

// 用户状态修改
export const updateUserStatus = (id: number, status: number) => {
  const data = {
    id,
    status,
  }
  return request({
    url: '/system/user/update-status',
    method: 'PUT',
    data,
  })
}

// 获取用户精简信息列表
export const getSimpleUserList = (): Promise<UserVO[]> => {
  return request({
    url: '/system/user/simple-list',
    method: 'GET',
  })
}

//导入用户
export const importUser = (updateSupport: boolean) => {
  return request({
    url: `/system/user/import?updateSupport=${updateSupport}`,
    method: 'GET',
  })
}
